package tcln.sors.model.core.dao;

import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.OptimisticLockingFailureException;

import tcln.sors.model.core.dom.Entity;

/**
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 * @param <E> 
 */
public class DefaultSorsHibernateDao<E extends Entity<Integer>> extends DefaultHibernateDao<E> {

    /**
     * {@inheritDoc}
     */
    @Override
    public E saveOrUpdate(E entity) throws DataAccessException, DataIntegrityViolationException,
            OptimisticLockingFailureException {
        E mergedEntity = merge(entity);
        return super.saveOrUpdate(mergedEntity);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public E saveOrUpdateAndFlush(E entity) throws DataAccessException, DataIntegrityViolationException,
            OptimisticLockingFailureException {
        E mergedEntity = merge(entity);
        return super.saveOrUpdateAndFlush(mergedEntity);
    }
}
